package org.supda.system.entity.system;

/**
 * Java运行时环境
 */
import java.net.InetAddress;
import java.net.UnknownHostException;

public class SystemPropertySingleton {
	
	private SystemPropertySingleton(){
		
	}
	
	private static SystemPropertySingleton sp = null;
	
	/**
	 * Java 运行时环境版本
	 */
	private  String systemVersion;
	/**
	 * Java 运行时环境供应商
	 */
	private  String systemVendor;
	/**
	 * Java 供应商的URL
	 */
	private  String systemVendorUrl;
	/**
	 * Java 安装目录
	 */
	private  String systemJavaHome;
	/**
	 * Java 虚拟机规范版本
	 */
	private  String systemJVMSpecificationVersion;
	/**
	 * Java 类格式版本号
	 */
	private  String systemClassVersion;
	/**
	 * Java类路径
	 */
	private  String systemClassPath;
	/**
	 * 加载库时搜索的路径列表
	 */
	private  String systemJavaClassPath;
	/**
	 * 加载库时搜索的路径列表
	 */
	private  String systemLibraryPath;
	/**
	 * 默认的临时文件路径
	 */
	private  String systemJavaIOTmpdir;
	/**
	 * 要使用的 JIT 编译器的名称
	 */
	private  String systemCompiler;
	/**
	 * 一个或多个扩展目录的路径
	 */
	private  String systemExtDirs;
	/**
	 * 操作系统的架构
	 */
	private  String systemOsName;
	/**
	 * 操作系统的名称
	 */
	private  String systemOsArch;
	/**
	 * 操作系统的版本
	 */
	private  String systemOsVersion;
	/**
	 * 文件分隔符
	 */
	private  String systemFileSeparator;
	/**
	 * 路径分隔符
	 */
	private  String systemPathSeparator;
	/**
	 * 行分隔符
	 */
	private  String systemLineSeparator;
	/**
	 * 用户的账户名称
	 */
	private  String systemUserName;
	/**
	 * 用户的主目录
	 */
	private  String systemUserHome;
	/**
	 * 用户的当前工作目录
	 */
	private  String systemUserDir;
	/**
	 * host ip
	 */
	private  String systemHostIP;
	/**
	 * host name
	 */
	private  String systemHostName;
	
	 InetAddress netAddress = getInetAddress();
	
	
	public static SystemPropertySingleton getSystemProperty(){
		
		if(sp == null){
			sp = new SystemPropertySingleton();
			
			sp.systemVersion = System.getProperty("java.version");
			sp.systemVendor = System.getProperty("java.vendor");
			sp.systemVendorUrl = System.getProperty("java.vendor.url");
			sp.systemJavaHome = System.getProperty("java.home");
			sp.systemJVMSpecificationVersion = System.getProperty("java.vm.specification.version");
			sp.systemClassVersion = System.getProperty("java.class.version");
			sp.systemClassPath = System.getProperty("java.class.path");
			sp.systemLibraryPath = System.getProperty("java.library.path");
			sp.systemJavaIOTmpdir = System.getProperty("java.io.tmpdir");
			sp.systemCompiler = System.getProperty("java.compiler");
			sp.systemExtDirs = System.getProperty("java.ext.dirs");
			sp.systemOsName = System.getProperty("os.name");
			sp.systemOsArch = System.getProperty("os.arch");
			sp.systemOsVersion = System.getProperty("os.version");
			sp.systemFileSeparator = System.getProperty("file.separator");
			sp.systemPathSeparator = System.getProperty("path.separator");
			sp.systemLineSeparator = System.getProperty("line.separator");
			sp.systemUserName = System.getProperty("user.name");
			sp.systemUserHome = System.getProperty("user.home");
			sp.systemUserDir = System.getProperty("user.dir");
			sp.systemHostIP = getHostIp(sp.netAddress);
			sp.systemHostName = getHostName(sp.netAddress);
		}
		
		return sp;
	}
	
	
	/**
	* 获取本地主机
	* @return 
	*/
	public  InetAddress getInetAddress() {
		try {
			return InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			System.out.println("unknown host!");
		}
		return null;
	} 
	
	/**
	* 通过InetAddress获取本地Ip
	* @param netAddress
	* @return 
	*/
	public static  String getHostIp(InetAddress netAddress) {
		if (null == netAddress) {
			return null;
		}
		String ip = netAddress.getHostAddress();
		return ip;
	}

	/**
	* 通过InetAddress获取本地主机的名字
	* @param netAddress
	* @return 
	*/
	public static  String getHostName(InetAddress netAddress) {
		if (null == netAddress) {
			return null;
		}
		String name = netAddress.getHostName();
		return name;
	}


	public  String getSystemVersion() {
		return systemVersion;
	}


	public  void setSystemVersion(String systemVersion) {
		this.systemVersion = systemVersion;
	}


	public  String getSystemVendor() {
		return systemVendor;
	}


	public  void setSystemVendor(String systemVendor) {
		this.systemVendor = systemVendor;
	}


	public  String getSystemVendorUrl() {
		return systemVendorUrl;
	}


	public  void setSystemVendorUrl(String systemVendorUrl) {
		this.systemVendorUrl = systemVendorUrl;
	}


	public  String getSystemJavaHome() {
		return systemJavaHome;
	}


	public  void setSystemJavaHome(String systemJavaHome) {
		this.systemJavaHome = systemJavaHome;
	}


	public  String getSystemJVMSpecificationVersion() {
		return systemJVMSpecificationVersion;
	}


	public  void setSystemJVMSpecificationVersion(
			String systemJVMSpecificationVersion) {
		this.systemJVMSpecificationVersion = systemJVMSpecificationVersion;
	}


	public  String getSystemClassVersion() {
		return systemClassVersion;
	}


	public  void setSystemClassVersion(String systemClassVersion) {
		this.systemClassVersion = systemClassVersion;
	}


	public  String getSystemClassPath() {
		return systemClassPath;
	}


	public  void setSystemClassPath(String systemClassPath) {
		this.systemClassPath = systemClassPath;
	}


	public  String getSystemJavaClassPath() {
		return systemJavaClassPath;
	}


	public  void setSystemJavaClassPath(String systemJavaClassPath) {
		this.systemJavaClassPath = systemJavaClassPath;
	}


	public  String getSystemLibraryPath() {
		return systemLibraryPath;
	}


	public  void setSystemLibraryPath(String systemLibraryPath) {
		this.systemLibraryPath = systemLibraryPath;
	}


	public  String getSystemJavaIOTmpdir() {
		return systemJavaIOTmpdir;
	}


	public  void setSystemJavaIOTmpdir(String systemJavaIOTmpdir) {
		this.systemJavaIOTmpdir = systemJavaIOTmpdir;
	}


	public  String getSystemCompiler() {
		return systemCompiler;
	}


	public  void setSystemCompiler(String systemCompiler) {
		this.systemCompiler = systemCompiler;
	}


	public  String getSystemExtDirs() {
		return systemExtDirs;
	}


	public  void setSystemExtDirs(String systemExtDirs) {
		this.systemExtDirs = systemExtDirs;
	}


	public  String getSystemOsName() {
		return systemOsName;
	}


	public  void setSystemOsName(String systemOsName) {
		this.systemOsName = systemOsName;
	}


	public  String getSystemOsArch() {
		return systemOsArch;
	}


	public  void setSystemOsArch(String systemOsArch) {
		this.systemOsArch = systemOsArch;
	}


	public  String getSystemOsVersion() {
		return systemOsVersion;
	}


	public  void setSystemOsVersion(String systemOsVersion) {
		this.systemOsVersion = systemOsVersion;
	}


	public  String getSystemFileSeparator() {
		return systemFileSeparator;
	}


	public  void setSystemFileSeparator(String systemFileSeparator) {
		this.systemFileSeparator = systemFileSeparator;
	}


	public  String getSystemPathSeparator() {
		return systemPathSeparator;
	}


	public  void setSystemPathSeparator(String systemPathSeparator) {
		this.systemPathSeparator = systemPathSeparator;
	}


	public  String getSystemLineSeparator() {
		return systemLineSeparator;
	}


	public  void setSystemLineSeparator(String systemLineSeparator) {
		this.systemLineSeparator = systemLineSeparator;
	}


	public  String getSystemUserName() {
		return systemUserName;
	}


	public  void setSystemUserName(String systemUserName) {
		this.systemUserName = systemUserName;
	}


	public  String getSystemUserHome() {
		return systemUserHome;
	}


	public  void setSystemUserHome(String systemUserHome) {
		this.systemUserHome = systemUserHome;
	}


	public  String getSystemUserDir() {
		return systemUserDir;
	}


	public  void setSystemUserDir(String systemUserDir) {
		this.systemUserDir = systemUserDir;
	}


	public  String getSystemHostIP() {
		return systemHostIP;
	}


	public  void setSystemHostIP(String systemHostIP) {
		this.systemHostIP = systemHostIP;
	}


	public  String getSystemHostName() {
		return systemHostName;
	}


	public  void setSystemHostName(String systemHostName) {
		this.systemHostName = systemHostName;
	}
}
